package com.liyuhan;

import java.io.*;

/**
 * Created by 李宇寒
 * Description:
 * 2019/6/26 0026 下午 9:16.
 */
public class Test {

    public static void readFile() {
        String path = "D://readme.txt";
        try {
            FileInputStream readFile = new FileInputStream(path);

            InputStreamReader reader = new InputStreamReader(readFile,"gbk");

            BufferedReader br = new BufferedReader(reader);
            String line;
            while((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            System.out.println(e);
        }
    }

    public static void writeFile() {
        try {
            FileOutputStream writeFile = new FileOutputStream("D://writeme.txt");

            OutputStreamWriter writer = new OutputStreamWriter(writeFile);

            BufferedWriter br = new BufferedWriter(writer);

            br.write("李宇寒\r\n");
            br.write("liyuhan");

            br.flush();
            System.out.println("写入文件完成！");

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String []args) {
        readFile();
        writeFile();
    }
}
